#include "Connection.h"


Connection::Connection(void)
{
}

Connection::~Connection(void)
{
	this->isRunning = FALSE;
}

void Connection::setNotifyTo(HWND hwnd){
	this->notifyTo = hwnd;
}

int Connection::sendData(BYTE *data, int len){
	return send(this->socket, (char *)data, len, 0);
}

DWORD WINAPI Connection::connection_service(VOID *p){
	Connection *_this = (Connection*)p;
	char buf[1024];
	int byteRead = 0;
	while(_this->isRunning){
		if((byteRead = recv(_this->socket, buf, 1024, 0))!=SOCKET_ERROR ){
			_this->queue->add((BYTE*)buf, byteRead);
			//MessageBox(_this->notifyTo,L"Receive data",L"Incoming connection",MB_ICONINFORMATION);
		}
	}

	return 0;
}
